package com.yufubao.api.controller.management.authorization;


import cn.dev33.satoken.stp.StpUtil;
import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.vo.management.authorization.ManagerAddVo;
import com.yufubao.service.service.management.authorization.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 后台管理系统-人员表
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-09-02 19:59:00
 */
@Api("后台管理系统-人员表")
@RestController
@RequestMapping("/applet/management/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
     * 退出登录
     */
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    @ApiOperation(value = "后台管理系统-退出登录")
    @SystemLog(info = "后台管理系统-退出登录")
    public ResponseResult logout() {
        StpUtil.logout();
        return ResponseResult.ok();
    }

    /**
     * 修改密码
     */
    @RequestMapping(value = "/updatePwd", method = RequestMethod.GET)
    @ApiOperation(value = "后台管理系统-修改密码")
    @SystemLog(info = "后台管理系统-修改密码")
    public ResponseResult updatePwd(@RequestParam("oldPwd") String oldPwd,
                                    @RequestParam("newPwd") String newPwd) {
        managerService.updatePwd(oldPwd, newPwd);

        return ResponseResult.ok();
    }


    //<editor-fold desc="人员管理功能">

    /**
     * 条件查询
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation(value = "后台管理系统-人员表列表")
    @SystemLog(info = "后台管理系统-人员表列表")
    public ResponseResult list(@RequestBody Map<String, Object> params) {
        PageUtils page = managerService.queryPage(params);

        return ResponseResult.okResultPage("page", page);
    }

//    /**
//     * 查询各级别人员信息
//     */
//    @RequestMapping(value = "/getAllLeveManager",method = RequestMethod.GET)
//    @ApiOperation(value = "后台管理系统-查询各级别人员信息")
//    @SystemLog(info = "后台管理系统-查询各级别人员信息")
//    public ResponseResult getAllLeveManager(){
//        PageUtils page = managerService.getAllLeveManager();
//
//        return ResponseResult.okResultPage("page", page);
//    }

    /**
     * 人员表新增下级
     */
    @RequestMapping(value = "/saveManager", method = RequestMethod.POST)
    @ApiOperation(value = "后台管理系统-人员表新增下级")
    @SystemLog(info = "后台管理系统-人员表新增下级")
    public ResponseResult saveManager(@RequestBody @Validated ManagerAddVo manager) {
        managerService.saveManager(manager);

        return ResponseResult.ok();
    }

    /**
     * 修改状态
     */
    @RequestMapping(value = "/updateStatus/{managerId}", method = RequestMethod.PUT)
    @ApiOperation(value = "后台管理系统-修改状态")
    @SystemLog(info = "后台管理系统-修改状态")
    public ResponseResult updateStatus(@PathVariable("managerId") Long managerId) {
        managerService.updateStatus(managerId);

        return ResponseResult.ok();
    }


    /**
     * 回显修改下级角色的信息
     */
    @RequestMapping(value = "/updateRoleEcho/{managerId}", method = RequestMethod.GET)
    @ApiOperation(value = "回显修改下级角色的信息")
    @SystemLog(info = "回显修改下级角色的信息")
    public ResponseResult updateRoleEcho(@PathVariable("managerId") Long managerId) {
        return ResponseResult.okResult(managerService.updateRoleEcho(managerId));
    }


    /**
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @description 更新下级角色信息
     * @author 31115
     * @date 2022/12/8 10:51
     */
    @RequestMapping(value = "/updateRole/{managerId}", method = RequestMethod.PUT)
    @ApiOperation(value = "更新下级角色信息")
    @SystemLog(info = "更新下级角色信息")
    public ResponseResult updateRole(@RequestBody List<Long> roleIds,
                                     @PathVariable("managerId") Long managerId) {
        managerService.updateRole(roleIds, managerId);
        return ResponseResult.ok();
    }

    /**
     * 删除下级
     */
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.DELETE)
    @ApiOperation(value = "后台管理系统-人员表删除")
    @SystemLog(info = "后台管理系统-人员表删除")
    public ResponseResult delete(@RequestBody Long[] managerIds) {
        managerService.remove(managerIds);

        return ResponseResult.ok();
    }
    //</editor-fold>=================================================================================


}
